//
//  Shop_Detail_Controller.m
//  pmmSS
//
//  Created by Mac book on 2017/9/22.
//  Copyright © 2017年 WTFSSD. All rights reserved.
//

#import "Shop_Detail_Controller.h"
#import "shop_detail_cell.h"


@interface Shop_Detail_Controller ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *leftTableView, *rightTableView;

@property (nonatomic,assign) BOOL collect_status;

@property (nonatomic,strong) UIButton *collect_btn;



@end

@implementation Shop_Detail_Controller

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];

    [self setUpNavBar];

}
- (void)viewDidLoad {
    [super viewDidLoad];

    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self createHeaderView];

        [self createLeftTabelView];
        [self createRightTabelView];
    
}
-(void)setUpNavBar{

    UILabel *title_label = [HMLabel createLabelWithText:@"店铺" andTextColor:[UIColor whiteColor] andBgColor:nil andFont:[UIFont fontWithName:default_fontname size:autoScaleW(20)] andTextAlignment:NSTextAlignmentCenter];
    title_label.frame = CGRectMake(0, 0, 100, 35);

    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_bgimage"] forBarMetrics:UIBarMetricsDefault];

    self.navigationItem.titleView = title_label;


    UIButton *leftBtn = [HMButton createButtonWithTitle:nil andTitleColor:nil andBgColor:nil andImage:[UIImage imageNamed:@"icon_arrow_left_white"] andBgImage:nil andSelecter:@selector(clickButton:) andTarget:self andTag:101];
    leftBtn.frame = CGRectMake(0, 0, autoScaleW(60), autoScaleW(30));
    [leftBtn setImageEdgeInsets:UIEdgeInsetsMake(autoScaleH(7), 0, autoScaleH(7), autoScaleW(50))];

    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];

    [self.navigationItem setLeftBarButtonItem:leftItem];
    
    
}

-(void)createHeaderView
{

    UIImageView *shop_imageView =  [[UIImageView alloc] init];

    // _iconImageView.backgroundColor = RGBA(253, 138, 40, 1);
    [shop_imageView setImage:[UIImage imageNamed:@"list_icon_shop"]];

    [self.view addSubview:shop_imageView];

    UILabel *shop_titile_label = [ HMLabel createLabelWithText:@"宇航钛合金" andTextColor:[UIColor blackColor]andBgColor:nil andFont:[UIFont fontWithName:default_fontname size:autoScaleW(18)] andTextAlignment:NSTextAlignmentLeft];

    [self.view addSubview:shop_titile_label];

    UIView *lineView = [[UIView alloc ] init];

    lineView.backgroundColor = View_BackgroundColor;

    [self.view addSubview:lineView];

    _collect_btn = [HMButton createButtonWithTitle:@"收藏店铺" andTitleColor:[UIColor grayColor] andBgColor:nil andImage:[UIImage imageNamed:@"collect_gray"] andBgImage:nil andSelecter:@selector(clickButton:) andTarget:self andTag:102];



    _collect_btn.titleLabel.font = [UIFont fontWithName:default_fontname size:autoScaleW(10)];

    [_collect_btn setImageEdgeInsets:UIEdgeInsetsMake(0, autoScaleW(10), autoScaleH(15), autoScaleW(10))];
     [self.view addSubview:_collect_btn];
    [_collect_btn setTitleEdgeInsets:UIEdgeInsetsMake(autoScaleH(30), -autoScaleH(30), 0, 0)];

    UIView *double_lineView = [[UIView alloc ] init];

    double_lineView.backgroundColor = View_BackgroundColor;

    [self.view addSubview:double_lineView];

    [shop_imageView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.mas_equalTo(autoScaleH(10));
        make.left.mas_equalTo(autoScaleW(10));
        make.width.mas_equalTo(autoScaleW(77));
        make.height.mas_equalTo(autoScaleH(58));

    }];

    [shop_titile_label mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.mas_equalTo(shop_imageView);
        make.left.mas_equalTo(autoScaleW(110));
        make.right.mas_equalTo(autoScaleW(-100));

    }];

    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.mas_equalTo(shop_imageView);
        make.height.mas_equalTo(autoScaleH(50));
        make.width.mas_equalTo(autoScaleW(1));
        make.right.mas_equalTo(autoScaleW(-60));
        
    }];

    [_collect_btn mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.mas_equalTo(shop_imageView);
        make.height.mas_equalTo(autoScaleH(50));
        make.width.mas_equalTo(autoScaleW(50));
        make.right.mas_equalTo(autoScaleW(-10));
    }];

    [double_lineView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.bottom.mas_equalTo(shop_imageView).offset(autoScaleH(20));
        make.height.mas_equalTo(autoScaleH(10));
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);

    }];


}

-(void)createLeftTabelView{

    _leftTableView = [[UITableView alloc]initWithFrame:CGRectMake(0,autoScaleH(88), autoScaleW(95), GET_FRAME_HEIGHT(self.view) - 64 - autoScaleH(88)) style:UITableViewStylePlain];

    _leftTableView.backgroundColor = View_BackgroundColor;
    _leftTableView.rowHeight = autoScaleH(50);

    _leftTableView.delegate = self ;
    _leftTableView.dataSource = self;

    [self.view addSubview:_leftTableView];

    [_leftTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];

}

-(void)createRightTabelView{


    _rightTableView = [[UITableView alloc]initWithFrame:CGRectMake(autoScaleW(95),autoScaleH(88), GET_FRAME_WIDTH(self.view) - autoScaleW(95), GET_FRAME_HEIGHT(self.view) - 64 - autoScaleH(88)) style:UITableViewStylePlain];

    _rightTableView.backgroundColor = View_BackgroundColor;
    _rightTableView.rowHeight = autoScaleH(95);
    _rightTableView.delegate = self ;
    _rightTableView.dataSource = self;

    [self.view addSubview:_rightTableView];


    [_rightTableView registerClass:[shop_detail_cell class] forCellReuseIdentifier:@"shop_detail_cell"];

}

#pragma mark : UITableViewDelegate,UITableViewDataSource

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    if ([tableView isEqual:self.leftTableView]) {
        return 10;

    } else if ([tableView isEqual:self.rightTableView]) {

        return 6;

    }
    return 0;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

   return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    if ([tableView isEqual:self.leftTableView]) {

        static NSString *identifier = @"UITableViewCell";

        UITableViewCell *leftCell = [_leftTableView dequeueReusableCellWithIdentifier:identifier];
        leftCell.selectionStyle  = UITableViewCellSelectionStyleNone;

        leftCell.textLabel.text = @"钢材";
        leftCell.textLabel.textAlignment = NSTextAlignmentCenter;
        leftCell.textLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:autoScaleW(12)];
        leftCell.backgroundColor = View_BackgroundColor;

        return leftCell;

    } else if ([tableView isEqual:self.rightTableView]) {
        static NSString *identifier = @"shop_detail_cell";

         shop_detail_cell *rightCell = [_rightTableView dequeueReusableCellWithIdentifier:identifier];

        return rightCell;

    }
    return nil;

}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {

    if ([tableView isEqual:_leftTableView]) {

        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        cell.textLabel.textColor = [UIColor blackColor];
        cell.backgroundColor = View_BackgroundColor;

    }


}
// 点击cell--本次选择的cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    if ([tableView isEqual:_leftTableView]) {

        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        cell.textLabel.textColor = [UIColor redColor];
        cell.backgroundColor = [UIColor whiteColor];
        
    }

}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{


    return section == 0?0:1;

}


-(void)clickButton:(UIButton *)button{

    switch (button.tag) {
        case 101:
        {
            [self.navigationController popViewControllerAnimated:YES];

        }
            break;
        case 102:
        {

            _collect_status = !_collect_status;

            if (_collect_status) {

                [self.collect_btn setImage: [UIImage imageNamed: @"collect_red"] forState: UIControlStateNormal];

            } else {

                [self.collect_btn setImage: [UIImage imageNamed: @"collect_gray"] forState: UIControlStateNormal];
                
            }

        }
            break;
            
        default:
            break;
    }
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
